package edu.cdnu.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import edu.cdnu.common.constant.MessageConstatnt;
import edu.cdnu.common.result.ResultEntity;
import edu.cdnu.pojo.RolePojo;
import edu.cdnu.pojo.StudentPojo;
import edu.cdnu.service.PermissionService;

/**
 * 没有权限的接口的Controller层
 * @author ASUS AsingZ
 */
@RestController
@RequestMapping("/permission")
public class PermissionController {

	@Autowired
	private PermissionService permissionService;
	
	/**
	 * 角色列表
	 * @return
	 */
	@GetMapping("/roleList")
	public ResultEntity<List<RolePojo>> selectRoleList(){
		return ResultEntity.createSuccessResult(permissionService.selectRoleList());
	}
	
	/**
	 * 通过账号获取角色Id<br/>
	 * 这里只判断教务管理员、教师、班主任三类用户的角色<br/>
	 * 因为账号都为6位，学生账号12位在前端可以判断、管理员特殊账号不用判断
	 * @param account
	 * @return
	 */
	@GetMapping("/roleId/{account}")
	public ResultEntity<Integer> selectRoleIdByTeacherAccountWith6(@PathVariable String account) {
		// 上面有了必须参数，这只判断是否为6位
		if(account.length() != 6) {
			return ResultEntity.createFailResult(MessageConstatnt.PARAMETER_EXCEPTION);
		}
		return ResultEntity.createSuccessResult(permissionService.selectRoleIdByAccount(account));
	}
	
	
	@RequestMapping("/test")
	public int test(HttpServletRequest request) {
		StudentPojo studentPojo=new StudentPojo();
		System.out.println(studentPojo.selectAll());
		return 1;
	}
	
}
